package es.mllacer.qqsm.util;

import java.util.List;

import android.content.Context;
import android.location.Address;
import android.location.Geocoder;

public class Utils {

	// PLAY PREFERENCES

	public static final String PLAY_PREFERENCES = "PlayPreferences";

	public static final String FIFTY_USED_PREFERENCE = "FiftyUsed";
	public static final String PHONE_USED_PREFERENCE = "PhoneUsed";
	public static final String AUDIENCE_USED_PREFERENCE = "AudienceUsed";

	public static final String FIFTY_SELECTED_PREFERENCE = "FiftySelected";
	public static final String PHONE_SELECTED_PREFERENCE = "PhoneSelected";
	public static final String AUDIENCE_SELECTED_PREFERENCE = "AudienceSelected";

	public static final String QUESTION_PREFERENCE = "Question";

	public static final String QUANTITY_PREFERENCE = "Quantity";

	// SETTINGS PREFERENCES

	public static final String SETTINGS_PREFERENCES = "SettingsPreferences";

	public static final String USER_PREFERENCE = "User";
	public static final String LONGITUDE_PREFERENCE = "Longitude";
	public static final String LATITUDE_PREFERENCE = "Latitude";
	public static final String FRIEND_PREFERENCE = "Friend";
	public static final String LOCATE_PREFERENCE = "Locate";
	public static final String LOCATION_PREFERENCE = "Location";

	// get Address method depending on the latitude and longitude

	public static String getAddress(Context context, double latitude,
			double longitude) {
		Geocoder geocoder = new Geocoder(context);
		List<Address> addresses = null;
		try {
			// Get just one address
			addresses = geocoder.getFromLocation(latitude, longitude, 1);
			if (addresses != null && !addresses.isEmpty()) {
				String locality = addresses.get(0).getLocality();
				String country = addresses.get(0).getCountryName();
				String address = "";

				if (locality != null) {
					address = locality + ", " + country;
				}
				return address;
			}
		} catch (Exception e) {
			// do nothing
		}
		return "";
	}
}
